import { ref,onMounted } from 'vue'
import Fuse from 'fuse.js'
/**
 * 提前返回要检索的数据集
*/
const list = [
    { id: 1, label: '段1', value: '有' },
    { id: 2, label: '段ffff1', value: 'you' },
    { id: 3, label: '段5551', value: 'value' },
    { id: 4, label: '段94++++1', value: '999' },
]
/**
 * 检索关键词
*/
const keyWord = ref(null)
/**
 * 检索结果
*/
const searchResult = ref([])
/**
 * 初始化
*/
function initFuse() {
    fuse.value = new Fuse(list, {
        shouldSort: true,
        threshold: 0.4,
        location: 0,
        distance: 100,
        minMatchCharLength: 1,
        keys: [{
            name: 'label',
            weight: 0.7
        }, {
            name: 'value',
            weight: 0.3
        }]
    })
}
const handleSearch = () => {
    if(keyWord.value){
        searchResult.value = fuse.value.search(keyWord.value)
    }else{
        searchResult.value = []
    }
}
onMounted(()=>{
    initFuse()
})